package modules.majiang.data
{
	


	/**
	 * 麻将堆的数据
	 * @author xumin.xu
	 */
	public class RestCardData
	{
		/**
		 * 当前应该显示的剩余麻将数
		 */
		[Bindable]
		public var showMajiangNum:int = 0;

		/**
		 * 桌面上剩余牌数
		 **/
		[Bindable]
		public var _restMajiangNum:int = 0;

		public function set restMajiangNum(value:int):void
		{
			_restMajiangNum = value;

			showMajiangNum = getShowIndex(_restMajiangNum);

			updateView();
		}

		public function get restMajiangNum():int
		{
			return _restMajiangNum;
		}

		/** 牌堆中麻将图片数组 */
		private var childrenCards:Array;

		public function RestCardData(tableDataModel:TableDataModel)
		{
			this.tableDataModel = tableDataModel;
		}

		/**
		 * 更新桌面上剩余牌显示
		 **/
		private function updateView():void
		{
			if (childrenCards == null)
				return;

			//牌堆中麻将图片数组
			var length:int = childrenCards.length;

			for (var i:int = 0; i < length; i++)
			{
				childrenCards[i].visible = i < showMajiangNum;
			}
		}

//		[Embed("resource/card/restCardLeft.png")]
		public static var restCardLeft:Class;

//		[Embed("resource/card/restCardMiddle.png")]
		public static var restCardMiddle:Class;

//		[Embed("resource/card/restCardRight.png")]
		public static var restCardRight:Class;

		/** 牌堆元件数据 */
		private static var _cardsInfo:Array;

		/**
		 * 计算 编号为index的麻将显示的位置
		 */
		public static function getShowIndex(index:int):int
		{
			var showIndex:int = index;
			if (index >= 100)
			{
				showIndex = index - 80;
			}
			else if (index >= 60)
			{
				showIndex = index - 40;
			}
			return Math.min(60, showIndex);
		}

		/**
		 * 获取编号index的麻将数据
		 **/
		public function getCardInfo(index:int):Object
		{
			var showIndex:int = getShowIndex(index);
			/*if (childrenCards && childrenCards[showIndex])
			{
				var image:Image = childrenCards[showIndex];
				var gameUI:GameUI = UIAllRefer.instance.getGameUIbyTableId(tableDataModel.tableDataFromLobby.tableID);
				
				var imagePosition:Point = gameUI.globalToLocal(image.localToGlobal(new Point(0, 0)));
				return {x: imagePosition.x, y: imagePosition.y, source: cardsInfo[showIndex].source}
			}*/
			return {x: 0, y: 0, source: restCardLeft};
		}

		public static function get cardsInfo():Array
		{
			if (_cardsInfo == null)
			{
				_cardsInfo = [];
				_cardsInfo[0] = {index: 0, x: 186, y: 292, childIndex: 0, source: restCardLeft};
				_cardsInfo[1] = {index: 1, x: 186, y: 281, childIndex: 1, source: restCardLeft};
				_cardsInfo[2] = {index: 2, x: 194, y: 301, childIndex: 2, source: restCardLeft};
				_cardsInfo[3] = {index: 3, x: 194, y: 290, childIndex: 3, source: restCardLeft};
				_cardsInfo[4] = {index: 4, x: 202, y: 310, childIndex: 4, source: restCardLeft};
				_cardsInfo[5] = {index: 5, x: 202, y: 299, childIndex: 5, source: restCardLeft};
				_cardsInfo[6] = {index: 6, x: 210, y: 319, childIndex: 6, source: restCardLeft};
				_cardsInfo[7] = {index: 7, x: 210, y: 308, childIndex: 7, source: restCardLeft};
				_cardsInfo[8] = {index: 8, x: 218, y: 328, childIndex: 8, source: restCardLeft};
				_cardsInfo[9] = {index: 9, x: 218, y: 317, childIndex: 9, source: restCardLeft};
				_cardsInfo[10] = {index: 10, x: 226, y: 337, childIndex: 10, source: restCardLeft};
				_cardsInfo[11] = {index: 11, x: 226, y: 326, childIndex: 11, source: restCardLeft};
				_cardsInfo[12] = {index: 12, x: 234, y: 346, childIndex: 12, source: restCardLeft};
				_cardsInfo[13] = {index: 13, x: 234, y: 335, childIndex: 13, source: restCardLeft};
				_cardsInfo[14] = {index: 14, x: 242, y: 355, childIndex: 14, source: restCardLeft};
				_cardsInfo[15] = {index: 15, x: 242, y: 344, childIndex: 15, source: restCardLeft};
				_cardsInfo[16] = {index: 16, x: 250, y: 364, childIndex: 16, source: restCardLeft};
				_cardsInfo[17] = {index: 17, x: 250, y: 353, childIndex: 17, source: restCardLeft};
				_cardsInfo[18] = {index: 18, x: 258, y: 373, childIndex: 18, source: restCardLeft};
				_cardsInfo[19] = {index: 19, x: 258, y: 362, childIndex: 19, source: restCardLeft};
				_cardsInfo[20] = {index: 20, x: 369, y: 376, childIndex: 20, source: restCardMiddle};
				_cardsInfo[21] = {index: 21, x: 369, y: 363, childIndex: 21, source: restCardMiddle};
				_cardsInfo[22] = {index: 22, x: 396, y: 376, childIndex: 22, source: restCardMiddle};
				_cardsInfo[23] = {index: 23, x: 396, y: 363, childIndex: 23, source: restCardMiddle};
				_cardsInfo[24] = {index: 24, x: 423, y: 376, childIndex: 24, source: restCardMiddle};
				_cardsInfo[25] = {index: 25, x: 423, y: 363, childIndex: 25, source: restCardMiddle};
				_cardsInfo[26] = {index: 26, x: 450, y: 376, childIndex: 26, source: restCardMiddle};
				_cardsInfo[27] = {index: 27, x: 450, y: 363, childIndex: 27, source: restCardMiddle};
				_cardsInfo[28] = {index: 28, x: 477, y: 376, childIndex: 28, source: restCardMiddle};
				_cardsInfo[29] = {index: 29, x: 477, y: 363, childIndex: 29, source: restCardMiddle};
				_cardsInfo[30] = {index: 30, x: 504, y: 376, childIndex: 30, source: restCardMiddle};
				_cardsInfo[31] = {index: 31, x: 504, y: 363, childIndex: 31, source: restCardMiddle};
				_cardsInfo[32] = {index: 32, x: 531, y: 376, childIndex: 32, source: restCardMiddle};
				_cardsInfo[33] = {index: 33, x: 531, y: 363, childIndex: 33, source: restCardMiddle};
				_cardsInfo[34] = {index: 34, x: 558, y: 376, childIndex: 34, source: restCardMiddle};
				_cardsInfo[35] = {index: 35, x: 558, y: 363, childIndex: 35, source: restCardMiddle};
				_cardsInfo[36] = {index: 36, x: 585, y: 376, childIndex: 36, source: restCardMiddle};
				_cardsInfo[37] = {index: 37, x: 585, y: 363, childIndex: 37, source: restCardMiddle};
				_cardsInfo[38] = {index: 38, x: 612, y: 376, childIndex: 38, source: restCardMiddle};
				_cardsInfo[39] = {index: 39, x: 612, y: 363, childIndex: 39, source: restCardMiddle};
				_cardsInfo[58] = {index: 58, x: 800, y: 292, childIndex: 40, source: restCardRight};
				_cardsInfo[59] = {index: 59, x: 800, y: 281, childIndex: 41, source: restCardRight};
				_cardsInfo[56] = {index: 56, x: 792, y: 301, childIndex: 42, source: restCardRight};
				_cardsInfo[57] = {index: 57, x: 792, y: 290, childIndex: 43, source: restCardRight};
				_cardsInfo[54] = {index: 54, x: 784, y: 310, childIndex: 44, source: restCardRight};
				_cardsInfo[55] = {index: 55, x: 784, y: 299, childIndex: 45, source: restCardRight};
				_cardsInfo[52] = {index: 52, x: 776, y: 319, childIndex: 46, source: restCardRight};
				_cardsInfo[53] = {index: 53, x: 776, y: 308, childIndex: 47, source: restCardRight};
				_cardsInfo[50] = {index: 50, x: 768, y: 328, childIndex: 48, source: restCardRight};
				_cardsInfo[51] = {index: 51, x: 768, y: 317, childIndex: 49, source: restCardRight};
				_cardsInfo[48] = {index: 48, x: 760, y: 337, childIndex: 50, source: restCardRight};
				_cardsInfo[49] = {index: 49, x: 760, y: 326, childIndex: 51, source: restCardRight};
				_cardsInfo[46] = {index: 46, x: 752, y: 346, childIndex: 52, source: restCardRight};
				_cardsInfo[47] = {index: 47, x: 752, y: 335, childIndex: 53, source: restCardRight};
				_cardsInfo[44] = {index: 44, x: 744, y: 355, childIndex: 54, source: restCardRight};
				_cardsInfo[45] = {index: 45, x: 744, y: 344, childIndex: 55, source: restCardRight};
				_cardsInfo[42] = {index: 42, x: 736, y: 364, childIndex: 56, source: restCardRight};
				_cardsInfo[43] = {index: 43, x: 736, y: 353, childIndex: 57, source: restCardRight};
				_cardsInfo[40] = {index: 40, x: 728, y: 373, childIndex: 58, source: restCardRight};
				_cardsInfo[41] = {index: 41, x: 728, y: 362, childIndex: 59, source: restCardRight};
			}
			return _cardsInfo;
		}

		private var tableDataModel:TableDataModel;
	}
}
